﻿@using TestConsole

@if (Controls != null)
{
    @for (int i = 0; i < Controls.Count; i++)
    {
        var ctl = Controls[i];
        if (ctl is InputInfo input)
        {
            if (input.GType == GType.none)
            {
                if (input.InputType == InputType.date)
                {
                    <DateTimePicker ShowLabel="true" DisplayText="@input.Label" @bind-Value="input.DateValue"></DateTimePicker>
                }
                else if (input.InputType == InputType.text)
                {
                    <BootstrapInput ShowLabel="true" DisplayText="@input.Label" @bind-Value="input.StringValue"></BootstrapInput>
                }
                else if (input.InputType == InputType.password)
                {
                    <BootstrapPassword ShowLabel="true" DisplayText="@input.Label" @bind-Value="input.StringValue"></BootstrapPassword>
                }
                else
                {
                    throw new Exception($"不支持{input.InputType}");
                }
            }
            else if (input.GType == GType.checkbox)
            {
                <CheckboxList ShowLabel="true" @bind-Value="@input.StringValue" Items="@GetSelectedItemsForInput(input)" DisplayText="@input.Label"></CheckboxList>
            }
            else if (input.GType == GType.radio)
            {
                <RadioList ShowLabel="true" TValue="string" Items="@GetSelectedItemsForInput(input)" @bind-Value="input.StringValue" DisplayText="@input.Label" ShowBorder="false">

                </RadioList>
            }
            else
            {
                throw new Exception($"不支持{input.GType}");
            }
        }
        else if (ctl is TextareaInfo area)
        {
            <Textarea ShowLabel="true" DisplayText="@area.Label" @bind-Value="area.StringValue"></Textarea>
        }
        else if (ctl is SelectInfo select)
        {
            if (select.IsMultiple)
            {
                <MultiSelect ShowLabel="true" Items="GetSelectedItemsForSelect(select)" DisplayText="@select.Label" @bind-Value="select.MultiStringValue"></MultiSelect>
            }
            else
            {
                <Select ShowLabel="true" Items="GetSelectedItemsForSelect(select)" DisplayText="@select.Label" @bind-Value="select.StringValue"></Select>
            }
        }
        else
        {
            throw new Exception($"{ctl.GetType().Name}目前代码不支持");
        }
    }
}
